package id.co.rho.scoring.cid.server.dao.impl;

import id.co.rho.scoring.cid.domain.TypeModelConfig;
import id.co.rho.scoring.cid.server.dao.TypeModelConfigDao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Component;

@Component
public class TypeModelConfigDaoImpl implements TypeModelConfigDao {

	@PersistenceContext
	EntityManager entityManager;

	@Override
	public List<TypeModelConfig> searchByCodeAndName(String code, String name) {
		return entityManager
				.createQuery(
						"from TypeModelConfig where lower(name) like :name and lower(code) like :code and deleted=false")
				.setParameter("name", '%' + name.toLowerCase() + '%')
				.setParameter("code", '%' + code.toLowerCase() + '%')
				.getResultList();
	}

	@Override
	public List<TypeModelConfig> findAll() {
		return entityManager.createQuery(
				"from TypeModelConfig where deleted=false").getResultList();
	}

}
